package lig.com.uw.bo;

import org.apache.log4j.Logger;

import java.io.FileOutputStream;
import java.io.PrintStream;
import java.math.BigDecimal;
import lig.com.LogWriter;
import lig.com.uw.dao.MessageDao;
import lig.com.uw.dto.TestDTO;
import lig.com.uw.dto.TestDTOList;





/**
 * @author Hjung
 *
 */
public class TestBO {

	private static final Logger logger = Logger.getLogger(TestBO.class);

	private static TestDTOList testDTOList;


	public static void main(String[] args) throws Exception  {
		// TODO Auto-generated method stub
		
		try {
				
			
			//initialize
			String  limitCnt = "1000";
			TestDTO inTestDTO = new TestDTO(); 
			
			BigDecimal pre_percentage = new BigDecimal("0");
			BigDecimal percentage = new BigDecimal("0");	
			System.out.println("start");
			
			
			//connection
			MessageDao messageDao =	MessageDao.getInstnace();
			inTestDTO.setLimitCnt(limitCnt);									
			TestDTOList testDTOList= messageDao.selectMybatis(inTestDTO);
			
		
			
			
			//output setting
			PrintStream out = new PrintStream(new FileOutputStream("D:/Workspace/Migration/TestBOoutput.txt"));					
			out.println("       ID     |Name");
			out.println("-------------------");
			
			int dtoCnt = testDTOList.getDtoList().size();
			System.out.println("-------------dtoCnt ::"+dtoCnt);
			
			for(int idx = 0;idx<dtoCnt;idx++)
			{	

				

				out.println(testDTOList.getDtoList().get(idx).getId()+"|"+testDTOList.getDtoList().get(idx).getGuestName());
				BigDecimal child = new BigDecimal(idx+1);
				BigDecimal parent = new BigDecimal(dtoCnt);
				
				pre_percentage = percentage;			
				percentage = child.divide(parent).multiply(BigDecimal.valueOf(100)).setScale(0, 4);
				
				if(!pre_percentage.equals(percentage)){					
					System.out.println("-------------Progress Ratio ::"+percentage+"% Done");
				}											
			}
			
			
			//finalize
			System.out.println("end");
			out.close();
			
			
			
		}  catch (Exception e) {	
			logger.debug("Exception : " +e.toString());		
			throw new Exception(e);
		} 
	}

}
